import sys

__author__ = 'mkompan'

from rggraphenv.symbolic_functions import var, tgamma, e ,cln

s, t = var('s t')
x = var('x')
fact = lambda x: tgamma(x+1)

res_d8_kazakov = {'I1': 1/fact(3),
                  'J1': -s/fact(3)/fact(4),
                  'J2': -t/fact(3)/fact(4),
                  'K1': s*s/fact(5)/fact(4),
                  'K2': t*t/fact(5)/fact(4),
                  'K3': s*(3*s*s-2*s*t+t*t)/fact(5)/fact(4)/fact(3)/9,
                  'K4': t*(3*t*t-2*s*t+s*s)/fact(5)/fact(4)/fact(3)/9,

                 'L1': (s**3*cln(-210))/fact(6)/fact(5)/fact(4)/fact(3),
                 'L2': (t**3*cln(-210))/fact(6)/fact(5)/fact(4)/fact(3),
                 'L3': (s**4*cln(-430)/21+s**3*t*cln(4)/9-s**2*t**2*cln(1)/18)/fact(6)/fact(5)/fact(4)/fact(3), #correct
                 'L4': (-s**2*t**2*cln(1)/18+s*t**3*cln(4)/9+t**4*cln(-430)/21)/fact(6)/fact(5)/fact(4)/fact(3),
                 'L5': (s**4*cln(-20)/3+s**3*t*cln(8)/9-s**2*t**2*cln(1)/9)/fact(6)/fact(5)/fact(4)/fact(3), #correct
                 'L6': (-s**2*t**2*cln(1)/9+s*t**3*cln(8)/9)/fact(6)/fact(5)/fact(4)/fact(3),
                 'L7': (-cln(45)/14*s**5+s**4*t*(cln(18)/7)+s**3*t**2*cln(-27)/14+s*s*t**3*(cln(9)/7)+s*t**4*cln(-9)/14)/fact(6)/fact(5)/fact(4)/fact(3),
                 'L8': (s*t**4*(cln(18)/7)+s**2*t**3*cln(-27)/14+s**3*t**2*(cln(9)/7)+t*s**4*cln(-9)/14-cln(45)/14*t**5)/fact(6)/fact(5)/fact(4)/fact(3), #corect
                 'L9': (s**5*cln(-15)/28+s**4*t*cln(25)/7/9+s**3*t**2*cln(-65)/7/4/9+s**2*t**3*cln(5)/42+s*t**4*(-cln(1)/28))/fact(6)/fact(5)/fact(4)/fact(3), #correct
                 'L10': (s**4*t*(-cln(1)/28)+s**3*t**2*cln(5)/42 + s**2*t**3*cln(-65)/7/4/9+t**4*s*cln(25)/7/9+t**5*cln(-15)/28)/fact(6)/fact(5)/fact(4)/fact(3),
                 'L11': cln(0),
                 'L12': cln(0),
                 'L13': cln(0),
                 'L14': cln(0),
                 'L15': cln(0),

                  }
print res_d8_kazakov


#D8_s_s_s_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.1M:result = 0.000347177061559275147
#D8_s_s_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.1M:result = -7.71577109669606447e-05
#D8_1|234||||:0|0_0_0||||:s|0|s|t|t/1|234||||:0|0_0_0||||:s|0|s|t|t_0_V3_E0.run.res.1M:result = 0.166666380789930679
#D8_s_1|234|3|45|||:0|0_0_0|0|0_0|||:s|0|t|0|t|s/1|234|3|45|||:0|0_0_0|0|0_0|||:s|0|t|0|t|s_0_V5_E-1.run.res.1M:result = -0.0138863238042842025
#D8_s_s_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s/1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s_0_V7_E-2.run.res.1M:result = 0.00203361304696674959
#D8_s_t_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.1M:result = 3.85783339864735573e-05
#D8_s_t_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s/1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s_0_V7_E-2.run.res.1M:result = 1.15723241185716754e-06



# D8_1|234||||:0|0_0_0||||:s|0|s|t|t/1|234||||:0|0_0_0||||:s|0|s|t|t_0_V3_E0.run.res.10000000:result = 0.166666801641045664
# D8_1|234||||:0|0_0_0||||:s|0|s|t|t/1|234||||:0|0_0_0||||:s|0|s|t|t_0_V3_E0.run.res.100000000:result = 0.166666737257660458
# D8_s_1|234|3|45|||:0|0_0_0|0|0_0|||:s|0|t|0|t|s/1|234|3|45|||:0|0_0_0|0|0_0|||:s|0|t|0|t|s_0_V5_E-1.run.res.100000000:result = -0.0069444395005259698
# D8_s_s_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s/1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s_0_V7_E-2.run.res.100000000:result = 0.000347222427445916069
# D8_s_s_s_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.100000000:result = 1.92902197684449618e-05
# D8_s_s_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.100000000:result = -1.28600777698412859e-05
# D8_s_s_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s_0_V7_E-2.run.res.100000000:result = 6.43009917744553122e-06
# D8_s_t_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t_0_V7_E-2.run.res.100000000:result = 6.4300638832171996e-06
# D8_s_t_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s_0_V7_E-2.run.res.100000000:result = -1.28601020109254184e-05
# D8_t_1|234|3|45|||:0|0_0_0|0|0_0|||:t|0|s|0|s|t/1|234|3|45|||:0|0_0_0|0|0_0|||:t|0|s|0|s|t_0_V5_E-1.run.res.100000000:result = -0.00694444116829172949
# D8_t_t_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:t|0|0|s|s|0|t/1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:t|0|0|s|s|0|t_0_V7_E-2.run.res.100000000:result = 0.000347220504630162444
# D8_t_t_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s/1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s_0_V7_E-2.run.res.100000000:result = 1.92901204043652127e-05

res_d8_mk =  {'I1': 0.166666380789930679,  # D8_1|234||||:0|0_0_0||||:s|0|s|t|t
              'J1': -0.0069444395005259698*s + 0*t,  # D8_s_1|234|3|45|||:0|0_0_0|0|0_0|||:s|0|t|0|t|s
              'J2': -0.00694444116829172949*t + 0*s,  # D8_t_1|234|3|45|||:0|0_0_0|0|0_0|||:t|0|s|0|s|t
              'K1': s**2*0.000347222427445916069,   # D8_s_t_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:s|0|0|t|t|0|s
              'K2': t**2*0.000347220504630162444,  # D8_s_t_1|234|345|5|5|6||:0|0_0_0|0_0_0|0|0|0||:t|0|0|s|s|0|t
              'K3': s**3*1.92902197684449618e-05+s**2*t*(-1.28600777698412859e-05)+s*t**2*6.4300638832171996e-06+t**3*0,   # D8_s_s_s_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:s|0|t|0|s|0|t
              'K4': s**3*0+s**2*t*(6.43009917744553122e-06)+s*t**2*(-1.28601020109254184e-05)+t**3*1.92901204043652127e-05,   # D8_t_t_t_1|23456|3|45|5|6||:0|0_0_1_0_0|0|0_0|0|0||:t|0|s|0|t|0|s

              'L1': s**3*(-1.68785995602744613e-05),
              'L2': t**3*(-1.68778695435609865e-05),
              'L3': s**4*(-1.64567102125066986e-06)+s**3*t*(3.57204561294340108e-08)+s*s*t*t*(-4.46518959518477966e-09), #correct s*s*t*t
              'L4': s*s*t*t*(-4.46518959518477966e-09)+s*t**3*(3.57204561294340108e-08)+t**4*(-1.64567102125066986e-06),
              'L5': s**4*(-2.75253142702371203e-07 -1.42726868721902996e-07 -3.44893147619749901e-08-8.33243335550604943e-08)+s**3*t*(7.14458251862796748e-08)+s*s*t*t*(-8.93056087494089887e-09), #correct s*s*t*t
              'L6': s*s*t*t*(-8.93056087494089887e-09)+s*t**3*(7.14458251862796748e-08)+t**4*(-2.75253142702371203e-07 -1.42726868721902996e-07 -3.44893147619749901e-08-8.33243335550604943e-08),
              'L7': s**5*(-2.58350887957834037e-07)+s**4*t*(2.06686192690137045e-07)+s**3*t**2*(-1.55011566907761635e-07)+s**2*t**3*(1.03337882470582075e-07)+s*t**4*(-5.16715122528733594e-08),
              'L8': s**4*t*(-5.16715122528733594e-08)+s**3*t**2*(1.03337882470582075e-07)+s**2*t**3*(-1.55011566907761635e-07)+s**1*t**4*(2.06686192690137045e-07)+t**5*(-2.58350887957834037e-07),  #correct t^5
              'L9': s*t**4*(-2.87039517787842645e-09)+s**2*t**3*(9.56890571755092227e-09)+s**3*t**2*(-2.07308801741647146e-08)+s**4*t*(2.55016905933046112e-08+4.50545680076137807e-09+1.88880929057826021e-09)+s**5*(-2.60895992478026868e-08-7.03329483134756389e-10-1.62670686265519564e-08), #correct s*s*t*t
              'L10': s**4*t*(-2.87039517787842645e-09)+s**3*t**2*(9.56890571755092227e-09)+s**2*t**3*(-2.07308801741647146e-08)+t**4*s*(2.55016905933046112e-08+4.50545680076137807e-09+1.88880929057826021e-09)+t**5*(-2.60895992478026868e-08-7.03329483134756389e-10-1.62670686265519564e-08),

              'L11': cln(0),
              'L12': cln(0),
              'L13': cln(0),
              'L14': cln(0),
              'L15': cln(0),
              }
for i in sorted(res_d8_mk.keys()):
    print i, "\t", (res_d8_kazakov[i].expand()).evalf() if i in res_d8_kazakov else None, "\n\t", res_d8_mk[i], \
        "\ndelta =", ((res_d8_kazakov[i].expand()).evalf()-res_d8_mk[i]).expand() if i in res_d8_kazakov else None
    print i, "\t", (res_d8_kazakov[i])*fact(6)*fact(5)*fact(4)*fact(3)
    print


sys.exit()

print
print
print "D=6"
print

res_d6_kazakov = {'K3': cln(1)/6,
                 'K4': cln(1)/6,
                 'L1': cln(0),
                 'L2': cln(0),
                 'L3': cln(1)/48,
                 'L4': cln(1)/48,
                 'L5': cln(1)/24,
                 'L6': cln(1)/24,
                 'L7': cln(0),
                 'L8': cln(0),
                 'L9': (t-s)/3/48,
                 'L10': (s-t)/3/48,
                 'L11': cln(0),
                 'L12': cln(0),
                 'L13': cln(0),
                 'L14': cln(0),
                 'L15': cln(0),
                 }


# D6_1|234|34567|5|6|67|7||:0|0_0_0|0_0_0_0_1|0|0|0_0|0||:s|0|0|t|t|0|0|s/1|234|34567|5|6|67|7||:0|0_0_0|0_0_0_0_1|0|0|0_0|0||:s|0|0|t|t|0|0|s_0_V11_E-1.run.res.10000000:result = 0.0208328082549803541
# D6_1|23456|34|45|567|6|||:0|0_0_1_0_0|0_0|0_0|0_0_0|0|||:t|0|s|0|0|0|s|t/1|23456|34|45|567|6|||:0|0_0_1_0_0|0_0|0_0|0_0_0|0|||:t|0|s|0|0|0|s|t_0_V11_E-1.run.res.10000000:result = 0.0416652289605569243
# D6_s_1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:s|0|t|0|0|t|s|0/1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:s|0|t|0|0|t|s|0_0_V11_E-1.run.res.10000000:result = -0.00694435447490225188
# D6_s_1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:t|0|s|0|0|s|t|0/1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:t|0|s|0|0|s|t|0_0_V11_E-1.run.res.10000000:result = 0.00694435967527374902
# D6_t_1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:s|0|t|0|0|t|s|0/1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:s|0|t|0|0|t|s|0_0_V11_E-1.run.res.10000000:result = 0.00694430532353083625
# D6_t_1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:t|0|s|0|0|s|t|0/1|23456|3|4567|57|7|7||:0|0_0_0_0_1|0|0_1_0_0|0_0|0|0||:t|0|s|0|0|s|t|0_0_V11_E-1.run.res.10000000:result = -0.00694409525342296833

res_d6_mk = {'K3': 0.166672811495946843,
                 'K4': 0.166630234959756984,
                 'L1': cln(0),
                 'L2': cln(0),
                 'L3': 0.0208328082549803541,
                 'L4': cln(1)/48,
                 'L5':  0.0416652289605569243,
                 'L6': cln(1)/24,
                 'L7': 0.,
                 'L8': 0.,
                 'L9': -0.00694435447490225188*s+0.006944359675273749026*t,
                 'L10': 0.00694430532353083625*s+(-0.00694409525342296833)*t,
                 'L11': cln(0),
                 'L12': cln(0),
                 'L13': cln(0),
                 'L14': cln(0),
                 'L15': cln(0),
                 }


for i in sorted(res_d6_kazakov.keys()):
    print i,"\t", (res_d6_kazakov[i].expand()).evalf(),"\n\t",res_d6_mk[i],"\ndelta =", ((res_d6_kazakov[i].expand()).evalf()-res_d6_mk[i]).expand()
    print
